package www.qiyue.Ditie;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class DiTie {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("ditie")
    public String test(){
        String path="/pms/pms_project";
        String sql="SELECT * from blade_menu where `path`='"+path+"'";
        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        sql(map);
        return null;
    }
    private void sql(Map<String, Object> map){
        long id = Long.parseLong(map.get("id").toString());
        String path = map.get("path").toString();
        String[] split = path.split("/");
        String code = split[split.length-1];
        /*String add="INSERT INTO `pms`.`blade_menu`( `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)" +
                " VALUES ( "+id+", '"+code+"_add', '新增', 'add', '"+path+"/add', 'plus', 1, 2, 1, 1, NULL, 0)";*/
        String edit="INSERT INTO `pms`.`blade_menu`( `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) " +
                "VALUES ( "+id+", '"+code+"_edit', '修改', 'edit', '"+path+"/edit', 'form', 2, 2, 2, 1, NULL, 0)";
        String view="INSERT INTO `pms`.`blade_menu`( `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) " +
                "VALUES ( "+id+", '"+code+"_view', '查看', 'view', '"+path+"/view', 'file-text', 4, 2, 2, 1, NULL, 0)";
        //jdbcTemplate.update(add);
        jdbcTemplate.update(edit);
        jdbcTemplate.update(view);
    }
}
